package com.shioirikukuri.common.until;
import javax.servlet.http.HttpServletRequest;

public class TokenUtils {
	// 统一请求头字段名
	private static final String AUTH_HEADER = "Authorization";
	private static final String TOKEN_PREFIX = "Bearer ";

	/**
	 * 从请求头中提取token
	 * @param request request HTTP 请求对象
	 * @return  Token 或 null（当格式无效时）
	 */
	public static String extractToken(HttpServletRequest request) {
		String authHeader = request.getHeader(AUTH_HEADER);
		if (authHeader != null && authHeader.startsWith(TOKEN_PREFIX)) {
			return authHeader.substring(TOKEN_PREFIX.length());
		}
		return null;
	}
}